package com.nju.edu.android_app;

import com.nju.edu.android_app.callback.ShowListener;
import com.weibo.sdk.android.api.StatusesAPI;
import com.weibo.sdk.android.demo.R;
import com.weibo.sdk.android.demo.R.menu;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class DetailActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_detail);
	    ViewGroup view =(ViewGroup) findViewById(R.id.detail);
	    DisplayMetrics dm = new DisplayMetrics();   
        getWindowManager().getDefaultDisplay().getMetrics(dm); 
        view.setMinimumHeight(dm.heightPixels);
		Intent intent = getIntent();
		long id = intent.getLongExtra("id", 0);
		StatusesAPI statusesAPI = new StatusesAPI(MainActivity.accessToken);
		statusesAPI.show(id, new ShowListener(this));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.detail, menu);
		return true;
	}
	
	public Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			Bundle bundle=msg.getData();
			Bitmap head =StreamItem.getBitmap(bundle.getString("head_url"));
			((ImageView)findViewById(R.id.detail_photo)).setImageBitmap(head);
			((TextView)findViewById(R.id.detail_name)).setText(bundle.getString("name"));
			((TextView)findViewById(R.id.detail_content)).setText(bundle.getString("text"));
			if(bundle.getString("pic_url")!=null)
			{
				Bitmap pic=StreamItem.getBitmap(bundle.getString("pic_url"));
				((ImageView)findViewById(R.id.detail_pic)).setImageBitmap(pic);
			}
			else {
				((ImageView)findViewById(R.id.detail_pic)).setVisibility(View.GONE);
			}
			if(bundle.getString("retweet_user")!=null)
			{
				((TextView)findViewById(R.id.retweet_user)).setText("@"+bundle.getString("retweet_user"));
				((TextView)findViewById(R.id.retweet_text)).setText(bundle.getString("retweet_text"));
			}
			else {
				((TextView)findViewById(R.id.retweet_user)).setVisibility(View.GONE);
				((TextView)findViewById(R.id.retweet_user)).setVisibility(View.GONE);
			}
			((TextView)findViewById(R.id.detail_source)).setText("来自  "+Html.fromHtml(bundle.getString("source")));
		}

	};
	
	public void back(View v)
	{
		this.finish();
	}

	public void comment(View v){
		Intent  i=new Intent(this, CommentActivity.class);
		i.putExtra("id", this.getIntent().getLongExtra("id", 0));
		startActivity(i);
	}
}
